home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / executeForEachObject.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.2 KB  |  113 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Copyright (C) 1997-1999 Alias|Wavefront,
  18. // a division of Silicon Graphics Limited.
  19. //
  20. // The information in this file is provided for the exclusive use of the
  21. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  22. // and incorporate this code into other products for purposes authorized
  23. // by the Alias|Wavefront license agreement, without fee.
  24. //
  25. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  26. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  27. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  28. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  29. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  30. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  31. // PERFORMANCE OF THIS SOFTWARE.
  32. //
  33. //
  34. // Alias|Wavefront Script File
  35. // MODIFY THIS AT YOUR OWN RISK
  36. // Creation Date:  Mar. 14, 1997
  37. //
  38. //<doc>
  39. //<name executeForEachObject>
  40. //<owner "Alias|Wavefront Unsupported">
  41. //
  42. //<synopsis>
  43. //    string[] executeForEachObject( string $inThisList[], string $thisCmd )
  44. //
  45. //<description>
  46. //        This procedure takes a list of object names and applies the
  47. //        command in "thisCmd" to each object.  The object name is
  48. //        substituted for a %s in the command.  
  49. //
  50. //<flags>
  51. //        string $inThisList[] - a list of object names to operate on
  52. //        string $thisCmd - a string with %s in it.
  53. //
  54. //<returns>
  55. //        An array of strings is returned containing
  56. //        the names of all results from executing this command on each
  57. //        applicable object.
  58. //
  59. //<examples>
  60. //
  61. //  Example 1. if "thisCmd" is a string that looks like:
  62. //          reverseCommand -ch off -rpo on %s;
  63. //  and curve1 and curve2 are in the given list, then the commands 
  64. //  that will be executed for each object will look like:
  65. //          reverseCommand -ch off -rpo on curve1;
  66. //          reverseCommand -ch off -rpo on curve2;
  67. //
  68. //  Example 2.  if "thisCmd" is a string that looks like:
  69. //          reverseProc( true, false, %s );
  70. //  and curve1 and curve2 are in the given list, then the commands 
  71. //  that will be executed for each object will look like:
  72. //          reverseProc( true, false, curve1 );
  73. //          reverseProc( true, false, curve2 );
  74. //
  75. //  Example 3.
  76. //          cone; sphere; select -all;
  77. //          string $cmd = "duplicate %s";
  78. //          string $itemList[] = `ls -sl`;
  79. //          select -d;
  80. //          string $results[] = executeForEachObject($itemList, $cmd);    
  81. //
  82. //</doc>
  83. //
  84. global proc string[] executeForEachObject( 
  85.     string $inThisList[], string $thisCmd )
  86. {
  87.     string $listOfExecutedObjects[];
  88.     string $results[];
  89.     int $numExecutions = 0;
  90.     int $numObjects = size($inThisList);
  91.     if( $numObjects > 0 ) {
  92.         int $i;
  93.         string $tmp;
  94.         for( $i=0; $i<$numObjects; $i+=1 ) {
  95.             if ( "" == $inThisList[$i] ) {
  96.                 $tmp = `substitute "%s" $thisCmd $inThisList[$i]`;
  97.             }
  98.             else {
  99.                 $tmp = `substitute "%s" $thisCmd ("\"" + $inThisList[$i] + "\"")`;
  100.             }
  101.             if( !catch( $results = evalEcho( $tmp ) )) {
  102.                 $numExecutions ++;
  103.                 int $numResults = size( $results );
  104.                 int $numExec = size( $listOfExecutedObjects );
  105.                 for( $n = 0; $n < $numResults; $n ++ ) {
  106.                     $listOfExecutedObjects[$numExec + $n] = $results[$n];
  107.                 }
  108.             }
  109.         }
  110.     }
  111.     return $listOfExecutedObjects;
  112. }
  113.